package com.qx.service;

import com.qx.mapper.ScDeployMapper;
import com.qx.mapper.SeckillCommodityMapper;
import com.qx.pojo.ScDeploy;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qx.pojo.SeckillCommodity;

@Service
public class SeckillCommodityServiceImpl extends ServiceImpl<SeckillCommodityMapper, SeckillCommodity> implements SeckillCommodityService{

    @Resource
    private SeckillCommodityMapper seckillCommodityMapper;

    @Resource
    private ScDeployMapper scDeployMapper;

    @Override
    public List<SeckillCommodity> listById(Integer deployId) {
        return seckillCommodityMapper.selectByDeployId(deployId);
    }

    @Override
    public Integer selectByCommodityId(Integer commodityId) {
        return seckillCommodityMapper.selectBycommodityId(commodityId);
    }

    @Override
    public long getSpikeTime() {
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        List<ScDeploy> list = scDeployMapper.selectByBeginTime(date);
        if (list.isEmpty()){
            return 0L;
        }else {
            Date beginTime = list.get(0).getBeginTime();
            return beginTime.getTime() - date.getTime();
        }
    }
}
